"""
封装接口发送请求
"""


# 导入模块
import requests
# 定义一个登录方法
def api_login(username,password):
  url = 'http://kumanxuan1.f3322.net:8096/MMS/Login/loginUser'
  data ={'username':username,'password':password}
  res = requests.post(url,data)
  cookie = {'cookie':res.headers['Set-Cookie']}
  print(cookie)
  return cookie


class SenMethod:
  @staticmethod
  def send_method(method,url,params=None,data=None,headers=None):
    # 判断方法
    if method == 'get':
      response = requests.request(method=method,url=url,params=params,headers=headers)
    elif method=='post':
      response = requests.request(method=method,url=url,data=data,headers=headers)
    else:
      print('请输入请求的方法')
    return response


if __name__ == '__main__':
  cookie = api_login('admin',12345)
  print(type(cookie))
  url = 'http://kumanxuan1.f3322.net:8096/MMS/Client/GetClient'
  mathod = 'post'
  data = {'cno':'1529'}

  res = SenMethod.send_method(mathod,url,data,headers=cookie)
  print(res)